package com.lineage.server.serverpackets;

import com.lineage.server.datatables.lock.CharBookReading;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.templates.L1BookMark;
import java.util.ArrayList;

public class S_BookMarkLogin extends ServerBasePacket {
  private byte[] _byte = null;
  
  public S_BookMarkLogin(L1PcInstance pc, boolean flag) {
    ArrayList<L1BookMark> bookList = CharBookReading.get()
      .getBookMarks(pc);
    writeC(64);
    writeC(42);
    writeH(128);
    writeC(2);
    if (flag) {
      for (int i = 0; i < 127; i++) {
        if (i <= bookList.size()) {
          writeC(0);
        } else if (i <= bookList.size() + 1) {
          writeC(1);
        } else if (i <= bookList.size() + 2) {
          writeC(2);
        } else if (i <= bookList.size() + 3) {
          writeC(3);
        } else if (i <= bookList.size() + 4) {
          writeC(255);
        } else {
          writeC(255);
        } 
      } 
    } else {
      for (int i = 0; i < 127; i++)
        writeC(255); 
    } 
    writeH(60);
    if (flag) {
      writeH(bookList.size());
      for (L1BookMark book : bookList) {
        writeD(book.getId());
        writeS(book.getName());
        writeH(book.getMapId());
        writeH(book.getLocX());
        writeH(book.getLocY());
      } 
    } else {
      writeH(0);
      writeD(0);
      writeS("");
      writeH(0);
      writeH(0);
      writeH(0);
    } 
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
